import Vue from 'vue'
//导入VueRouter
import VueRouter from 'vue-router'
import routes from './routes'
//设置VueRouter
Vue.use(VueRouter)
/**
 * 由于vue-router版本的问题会导致如下错误
 * Avoided redundant navigation to current location: "/discovery/artist/cat/1001".
    NavigationDuplicated: Avoided redundant navigation to current location: "/discovery/artist/cat/1001".
    解决它的办法是重写复写router.push和router.replace方法，具体做法如下所示
 */

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

const originalPush2 = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location) {
    return originalPush2.call(this, location).catch(err => err)
}


/*
    创建router对象,VueRouer的构造函数中传递的是一个配置对象
    routes:路由配置集合
    mode:路由模式，常见的路由模式有hash,history
*/
const router = new VueRouter({
    routes,
    mode: 'hash'
})
//导出router
export default router